#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=310;
int n,cnt,fa[MAXN],ans;
struct edge
{
	int u,v,val;
	bool operator<(const edge b)const
	{
		return val<b.val;
	}
}e[MAXN*MAXN*2];
int getfa(int x)
{
	return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)e[++cnt]=(edge){0,i,read()},fa[i]=i;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
		{
			int x=read();
			if(i==j)continue;
			e[++cnt]=(edge){i,j,x};
		}
	sort(e+1,e+1+cnt);
	for(int i=1;i<=cnt;++i)
	{
		int a=getfa(e[i].u),b=getfa(e[i].v);
		if(a==b)continue;
		fa[a]=b;
		ans+=e[i].val;
	}
	printf("%d\n",ans);
	return 0;
}
